package com.yhsimon.realm.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhsimon.realm.member.entity.user.LoginRecordEntity;
import com.yhsimon.realm.member.service.LoginRecordService;
import com.yhsimon.realm.member.mapper.LoginRecordMapper;
import com.yhsimon.realm.member.vo.user.LoginRecordVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 19819
 * @description 针对表【ums_login_record(用户登录记录表)】的数据库操作Service实现
 * @createDate 2024-05-14 13:29:00
 */
@Service
public class LoginRecordServiceImpl extends ServiceImpl<LoginRecordMapper, LoginRecordEntity>
        implements LoginRecordService {

    @Autowired
    private LoginRecordMapper loginRecordMapper;


    @Override
    public List<LoginRecordVo> getLoginRecordInfo(int currentPage, int size, long userId) {
        Page<LoginRecordEntity> page = new Page<>(currentPage, size);
        List<LoginRecordEntity> loginRecordEntityList = loginRecordMapper.selectList(page, new QueryWrapper<LoginRecordEntity>().eq("user_id", userId).orderByDesc("create_time"));
        List<LoginRecordVo> loginRecordVoList = new ArrayList<>();
        for (LoginRecordEntity loginRecordEntity : loginRecordEntityList) {
            LoginRecordVo loginRecordVo = new LoginRecordVo();
            BeanUtils.copyProperties(loginRecordEntity, loginRecordVo);
            loginRecordVoList.add(loginRecordVo);
        }
        return loginRecordVoList;
    }
}




